<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>回调函数ref</title>
  <style>

  </style>
</head>

<body>
<!-- 创建test -->
<div id="test"></div>
<!-- 引入核心库 -->
<script src="../js/react.development.js"></script>
<!-- 引入react操作DOM支持库 -->
<script src="../js/react-dom.development.js"></script>
<!-- 引入babel 用于将jsx转为js -->
<script src="../js/babel.min.js"></script>
<!-- 引入prop-types 用于对组件标签属性进行限制 -->
<script src="../js/prop-types.js"></script>
<script type="text/babel">  // 此处引入一定要写babel
class Demo extends React.Component {

  state = {
    isHot: true
  }

  render() {
    const { isHot:showHot } = this.state;
    return (
      <div>
        <h2>今天天气是{ showHot ? '炎热' : '寒冷' }</h2>
        <label>
          { /*<input ref={ (currentNode) => {  this.input1 = currentNode } } type="text"/>*/}
          <input type="text" ref={ this.saveInput }/>
        </label>
        <button onClick={ this.showData }>点击提示输入的数据</button>
        <button onClick={ this.updateWeather }>点击我改变天气</button>
      </div>
    )
  }
  saveInput = (currentNode) => {
    this.input1 = currentNode;
  }
  showData = () => {
    const input = this.input1.value;
    alert(input)
  }
  updateWeather = () => {
    const { isHot } = this.state;
  //  更新状态
    this.setState({ isHot: !isHot });
  }
}

ReactDOM.render(<Demo/>, document.getElementById("test"))
</script>
</body>

</html>